package com.belizer.demo.map;

import java.util.HashMap;
import java.util.LinkedHashMap;

public class Demo {
    public static void main(String[] args) {
        //LinkedHashMap保证了插入顺序与获取顺序一致
        LinkedHashMap<String,String> map = new LinkedHashMap<>();
        map.put("3","1k");
        map.put("1","2k");
        System.out.println(map);


        // key 为 “1”在容量为8，16，32三个map集合的位置
        HashMap<String,String> map2 = new HashMap(8);
        map2.put("3","1k");
        map2.put("1","2k");
        System.out.println("容量为8时，idx为 " + (7&(("1".hashCode())^("1".hashCode() >>> 16))));


        HashMap<String,String> map3 = new HashMap(16);
        map3.put("3","1k");
        map3.put("1","2k");
        System.out.println("容量为16时，idx为 " + (15&(("1".hashCode())^("1".hashCode() >>> 16))));

        HashMap<String,String> map4 = new HashMap(32);
        map4.put("3","1k");
        map4.put("1","2k");
        System.out.println("容量为32时，idx为 " + (31&(("1".hashCode())^("1".hashCode() >>> 16))));
    }
}
